//package com.matt.foundation.ext.mq.impl;
//
//import com.aliyun.openservices.ons.api.Action;
//import com.aliyun.openservices.ons.api.Message;
//import com.matt.commons.constant.MQConstant;
//import com.matt.commons.utils.JsonUtil;
//import com.matt.foundation.ext.mq.MQConsumer;
//import com.matt.foundation.ext.mq.MQSender;
//import com.matt.service.MQMessageService;
//import com.matt.service.SchedulerService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Service;
//
//import javax.transaction.Transactional;
//
//import java.util.Map;
//
//import static com.matt.commons.constant.MQConstant.BASE_TAG.SCHEDULER_RESULT;
//import static com.matt.commons.constant.MQConstant.TOPIC.BASE;
//
///**
// * *******************************
// * Created by Ron.
// * form com.matt
// * on 2018/12/24
// * *******************************
// */
//@Service
//@Slf4j
//public class MQConsumerImpl implements MQConsumer {
//
//    @Autowired
//    private MQSender mqSender;
//
//    @Value("${spring.profiles.active}")
//    private String env;
//
//    @Autowired
//    private SchedulerService schedulerService;
//
//    @Autowired
//    private MQMessageService mqMessageService;
//
//    @Transactional
//    @Override
//    public Action consume(Message message, String content) {
//        String tag = message.getTag();
//        if (tag.equals(MQConstant.CRM_TAG.SCHEDULER_DAILY.codeOf()))
//            return processDailyScheduler(message, content);
//
//
//
//        return Action.CommitMessage;
//    }
//
//    private Action processDailyScheduler(Message message, String content) {
//        Map response = JsonUtil.readToMap(content);
//        Boolean notice = Boolean.valueOf(response.get("Q_notice").toString());
//
//        try {
//            String time = response.get("Q_time").toString();
//            boolean result = schedulerService.dailyClearTask(time);
//            response.put("Q_result", result);
//            mqMessageService.saveAndRefresh(message, MQConstant.ConsumeStatus.SUCCESS.codeOf());
//            mqSender.sendMsg(String.format(BASE.codeOf(), env), SCHEDULER_RESULT.codeOf(), message.getKey(), JsonUtil.toJson(response));
//        } catch (Exception e){
//            e.printStackTrace();
//            log.error("got daily tasks exception", e);
//            if (notice){
//                response.put("Q_result", false);
//                mqSender.sendMsg(String.format(BASE.codeOf(), env), SCHEDULER_RESULT.codeOf(), message.getKey(), JsonUtil.toJson(response));
//            }
//        }
//        return Action.CommitMessage;
//    }
//}
